define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ad/index',
                    add_url: 'ad/add',
                    edit_url: 'ad/edit',
                    del_url: 'ad/del',
                    multi_url: 'ad/multi',
                    table: 'ad',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id') ,operate:false},
                        {field: 'advertising_id', title: __('Advertising_id'), searchList: $.getJSON('ajax/advertising?search=a&field=row[advertising_id]')},
                        {field: 'title', title: __('Title')},
                        {field: 'type_text', title: __('Type'), operate:false},
                        {field: 'status', title: __('Status'), formatter: Controller.api.formatter.status, operate:false},

                        //{field: 'createTime', title: __('CreateTime'), formatter: Table.api.formatter.datetime, operate:false},
                        //{field: 'updateTime', title: __('UpdateTime'), formatter: Table.api.formatter.datetime, operate:false},
                        {field: 'action', title: __('Action'), operate:false},
                        {field: 'startTime', title: __('StartTime'), formatter: Table.api.formatter.datetime, operate:false},
                        {field: 'endTime', title: __('EndTime'), formatter: Table.api.formatter.datetime, operate:false},
                        {field: 'image', title: __('Image'), formatter: Table.api.formatter.image, operate:false},
                        {field: 'next', title: __('Next'), operate:false},
                        {field: 'status', title: __('Status'), formatter: Controller.api.formatter.status, operate:false},
                        {field: 'weigh', title: __('Weigh'), operate:false},
                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                status: function (value, row, index) {
                    //添加上btn-change可以自定义请求的URL进行数据处理
                    if(value==1){
                        return '启用';
                    }else{
                        return '<span style="color: red;">禁用</span>'
                    }

                }
            }
        }
    };
    return Controller;
});